<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户管理 - 学生能力分管理系统</title>
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f5f5f5;
        }
        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }
        header {
            background-color: #333;
            color: white;
            padding: 15px 0;
            margin-bottom: 20px;
        }
        nav {
            display: flex;
            justify-content: space-between;
            align-items: center;
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 20px;
        }
        .nav-links {
            display: flex;
            gap: 20px;
        }
        .nav-links a {
            color: white;
            text-decoration: none;
        }
        .nav-links a:hover {
            text-decoration: underline;
        }
        .user-info {
            display: flex;
            align-items: center;
            gap: 15px;
        }
        .logout-button {
            background-color: #f44336;
            color: white;
            border: none;
            padding: 8px 16px;
            border-radius: 4px;
            cursor: pointer;
            text-decoration: none;
        }
        .logout-button:hover {
            background-color: #d32f2f;
        }
        h1 {
            color: #333;
            margin-bottom: 20px;
        }
        .add-user-button {
            background-color: #4CAF50;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 4px;
            cursor: pointer;
            text-decoration: none;
            margin-bottom: 20px;
            display: inline-block;
        }
        .add-user-button:hover {
            background-color: #45a049;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            background-color: white;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }
        th, td {
            padding: 12px 15px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }
        th {
            background-color: #4CAF50;
            color: white;
        }
        tr:hover {
            background-color: #f5f5f5;
        }
        .action-buttons {
            display: flex;
            gap: 10px;
        }
        .edit-button {
            background-color: #2196F3;
            color: white;
            border: none;
            padding: 6px 12px;
            border-radius: 4px;
            cursor: pointer;
            text-decoration: none;
        }
        .edit-button:hover {
            background-color: #0b7dda;
        }
        .delete-button {
            background-color: #f44336;
            color: white;
            border: none;
            padding: 6px 12px;
            border-radius: 4px;
            cursor: pointer;
            text-decoration: none;
        }
        .delete-button:hover {
            background-color: #d32f2f;
        }
        .error {
            color: red;
            text-align: center;
            margin-bottom: 15px;
        }
        .success {
            color: green;
            text-align: center;
            margin-bottom: 15px;
        }
    </style>
</head>
<body>
    <header>
        <nav>
            <div class="nav-links">
                <a href="{{ url_for('index') }}">首页</a>
                {% if role == 'admin' %}
                <a href="{{ url_for('user_management') }}">用户管理</a>
                {% endif %}
                <!-- 其他导航链接 -->
            </div>
            <div class="user-info">
                <span>欢迎，{{ username }} ({{ role }})</span>
                <a href="{{ url_for('logout') }}" class="logout-button">注销</a>
            </div>
        </nav>
    </header>
    <div class="container">
        <h1>用户管理</h1>
        {% if error %}
            <div class="error">{{ error }}</div>
        {% endif %}
        {% if success %}
            <div class="success">{{ success }}</div>
        {% endif %}
        <a href="{{ url_for('register') }}" class="add-user-button">添加新用户</a>
        <table>
            <thead>
                <tr>
                    <th>ID</th>
                    <th>用户名</th>
                    <th>角色</th>
                    <th>创建时间</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {% for user in users %}
                <tr>
                    <td>{{ user.id }}</td>
                    <td>{{ user.username }}</td>
                    <td>{{ '管理员' if user.role == 'admin' else '普通用户' }}</td>
                    <td>{{ user.created_at.strftime('%Y-%m-%d %H:%M:%S') }}</td>
                    <td>
                        <div class="action-buttons">
                            <a href="{{ url_for('edit_user', user_id=user.id) }}" class="edit-button">编辑</a>
                            {% if user.id != current_user_id %}
                            <a href="{{ url_for('delete_user', user_id=user.id) }}" class="delete-button" onclick="return confirm('确定要删除用户 {{ user.username }} 吗？')">删除</a>
                            {% else %}
                            <span class="delete-button" style="background-color: #ccc; cursor: not-allowed;">删除</span>
                            {% endif %}
                        </div>
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
</body>
</html>